package com.hexb.smh.service.impl;

import com.hexb.core.common.Page;
import com.hexb.core.service.Pagination;
import com.hexb.smh.entity.LoginLog;
import com.hexb.smh.entity.OperationLog;
import com.hexb.smh.entity.param.log.LoginLogQueryParam;
import com.hexb.smh.entity.param.log.OperationLogQueryParam;
import com.hexb.smh.entity.view.LoginLogView;
import com.hexb.smh.entity.view.OperationLogView;
import com.hexb.smh.mapper.OperationLogMapper;
import com.hexb.smh.service.IOperationLogService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : hexb
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OperationLogService implements IOperationLogService {

    @NonNull
    private final OperationLogMapper operationLogMapper;

    @Override
    public int save(OperationLog ol) {
        return operationLogMapper.save(ol);
    }

    @Override
    public Page<OperationLogView> search(OperationLogQueryParam param, int pageSize, int pageNum) {
        return Pagination.pageCommonAnyType(param, pageNum, pageSize, operationLogMapper::search);
    }

    @Override
    public int save(LoginLog log) {
        return operationLogMapper.saveLoginLog(log);
    }

    @Override
    public Page<LoginLogView> search(LoginLogQueryParam param, int pageSize, int pageNum) {
        return Pagination.pageCommonAnyType(param, pageNum, pageSize, operationLogMapper::searchLoginLog);
    }
}
